home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1836 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: microl4.microlise.UUCP!news
  2. From: andrewg@microlise.co.uk   (Andrew Gierth)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: copy ctor and derived classes
  5. Date: 13 Jan 1996 07:22:52 GMT
  6. Organization: Microlise Engineering Ltd.
  7. Message-ID: <4d7mkc$fkm@microl4.microlise.UUCP>
  8. References: <DL38zz.50K@Virginia.EDU> <4d6u37$3b7@news.bridge.net>
  9. Reply-To: andrewg@microlise.co.uk  (Andrew Gierth)
  10. NNTP-Posting-Host: andrewg.microlise.uucp
  11. X-NNTP-Posting-Host: microl.demon.co.uk
  12. X-Newsreader: IBM NewsReader/2 v1.2.5
  13.  
  14. In <4d6u37$3b7@news.bridge.net>, David Byrden <100101.2547@compuserve.com> writes:
  15. >
  16. >Greg;
  17. >
  18. >>>  how can I invoke the base class's copy constructor in the
  19. >>> intialization list the derived class doesn't have to deal 
  20. >>> with all of the little bits of the base class?
  21. >
  22. >The derived class has no RIGHT to deal with all the bits of the 
  23. >base class. They can be private.
  24. >
  25. >Here's what to do:
  26. >
  27. >Derived::Derived( const Derived& rhs )      // copy ctor
  28. > : Base( *this )                           // invoke base's copy ctor
  29. >{
  30. >
  31. >}
  32. >
  33. >The copy ctor which the compiler can silently fgenerate for you,will do 
  34. >this a utomatically.
  35.  
  36. You're trying to copy the object to itself!
  37.  
  38. Don't you mean:
  39.  
  40. Derived::Derived(const Derived& rhs)
  41.   : Base(rhs)
  42. {
  43. }
  44.  
  45. -- Andrew  (andrewg@microlise.co.uk)
  46.  
  47. [.sig under construction]
  48.  
  49.